const app = getApp();
Page({
    data: {
			cdnUrl: '',
			isWxapp: true,
			userInfo: {
			  id: 0,
			  avatar: '/assets/images/avatar.png',
			  nickname: '游客',
			  balance: 0,
			  score: 0,
			  level: 0
			},
			/* 自定义导航栏参数 */
			loading: false,
			color: '#FFFFFF',
			background: '#02B3BA',
			show: true,
			animated: false,
			back: false,
			title: "我的",
		
			/* 自定义tabbar */
			list: [
				{
						"pagePath": "/page/index/index",
						"iconPath": "/images/index.png",
						"selectedIconPath": "/images/index-selected.png",
						"text": "抢单"
				},
				{
						"pagePath": "/page/order_list/index",
						"iconPath": "/images/timetable.png",
						"selectedIconPath": "/images/timetable-selected.png",
						"text": "订单"
				},
				
				{
						"pagePath": "/page/mine/mine",
						"iconPath": "/images/mine.png",
						"selectedIconPath": "/images/mine-selected.png",
						"text": "我的"
				},
			],
			currentTab: 3
    },
	tabChange(e) {
		this.setData({
			currentTab: e.detail.index
		})
		wx.reLaunch({
		  url: e.detail.item.pagePath
		})
	},
	onLoad: function () {
		var that = this;
		that.setData({
			cdnUrl: app.cdnUrl,
		});
	},
  onShow: function () {
    var that = this;
   //  if (app.globalData.userInfo) {
   //    setTimeout(function(){
   //      that.setData({
   //        userInfo: app.globalData.userInfo,
   //      });
   //    },3000)
   //  }else{
  	// 	app.check(that);
  	// }
    if (app.globalData.userInfo) {
      that.getUserInfo();
    	if(!app.globalData.userInfo.rider_apply){
    		app.showApply();
    		return false;
    	}else{
        if(app.globalData.userInfo.rider_apply.status == 0 || app.globalData.userInfo.rider_apply.status == 2){
          app.showApply();
          return false;
        }
      }
      that.setData({ 
        userInfo: app.globalData.userInfo,
      });
    }else{			
    	setTimeout(function () {
    		if (app.globalData.userInfo) {
    			wx.reLaunch({
    				url: '/page/mine/index'
    			});
    		}else{
    			app.check(function(ret){}, '/page/mine/index');
    		}
    	}, 500)
    }
  },
  /* 获取用户信息*/
  getUserInfo: function(){
    var that = this;
    app.request("/api/timetable.user/userInfo", {}, function (data, ret) {
      // app.success('头像上传成功!');
      app.globalData.userInfo = data.userInfo;
      that.setData({
        userInfo: data.userInfo,
        signstatus: data.userInfo.signstatus
      });
    }, function (data, ret) {
      // app.error(ret.msg);
    });
  },
  
  changeSignstatus: function(){
    var that = this;
    var signstatus = '';
    if(that.data.userInfo.signstatus==1){
      signstatus = 0;
    }else if(that.data.userInfo.signstatus==0){
      signstatus = 1;
    }
    app.request("/api/timetable.user/changeSignstatus", {signstatus: signstatus}, function (data, ret) {
      app.globalData.userInfo = data.userInfo;
      that.setData({
        userInfo: data.userInfo,
        signstatus: data.userInfo.signstatus
      });
      app.success(ret.msg);
    }, function (data, ret) {
      app.error(ret.msg);
    });
  }
});
